package measure;

import java.util.HashMap;
import java.util.Map.Entry;

public class DocumentFreq {

	HashMap<String, Integer> _documentFreqDict;
	
	public DocumentFreq() {
		_documentFreqDict = new HashMap<String, Integer>();
		
	}

	public boolean containsKey(String key) {
		return _documentFreqDict.containsKey(key);
	}

	public void put(String word, int freq) {
		_documentFreqDict.put(word, freq);
	}
	
	public void put(String word) {
		if (_documentFreqDict.containsKey(word)) {
			int freq = _documentFreqDict.get(word);
			_documentFreqDict.put(word, freq + 1);			
		} else {
			_documentFreqDict.put(word, 1);
		}
	}
	
	public int getDF(String word) {
		if (_documentFreqDict.containsKey(word)) {
			return _documentFreqDict.get(word);
		} else {
			return 0;
		}
	}
	
	public double getIDF(String word) {
		if (getDF(word)==0) {
			return 0;
		} else {
			return Math.log10(_documentFreqDict.size()/getDF(word));
		}
	}
	
	public void showDF() {
		for (Entry<String, Integer> e : _documentFreqDict.entrySet()) {
			System.out.println(e.getKey() + ", " + e.getValue());
		}
	}
	
	public int getSize() {
		return _documentFreqDict.size();
	}
	
	public HashMap<String, Integer> documentFreqDict() {
		return _documentFreqDict;
	}

	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
